//基于textarea文本框Zepto select单选 包装集的插件选择
(function($){
    $.fn.textarea = function(options){
        var opts = $.extend({
            text_title: '',                 //文本（标题值）
            select_text:'.select_text',     //默认为当前select文本值
            hidden: '',                     //select隐藏表单值
            className: 'textarea_content',  //弹出的类名
            callback:function(hiddenVal){},  //成功确定以后执行的回调函数 当前表单隐藏val值
            pop_content:'#pop_content'       //弹出层的文本内容默认值
        },options||{}); //合并内容
        //直接指向this
        var othis = this;
        //隐藏表单有值时
        if($(opts.hidden).val() != ''){
            othis.find('.select_text').html(mSubstr($(opts.hidden).val(),24));
        }
        othis.click(function(){
            var content =  othis.find(opts.hidden).html();
            var pop_content = str_trim(opts.pop_content);
            var str = "";
            str += '<div class="textarea">';
            str += '<textarea name="'+pop_content+'" id="'+pop_content+'" cols="" rows="" placeholder="请输入'+opts.text_title+'">'+content+'</textarea>';
            str += '<span class="clear">清空</span>';
            str += '</div>';
            layer.open({
                title: [
                    opts.text_title,
                    'background-color:#00c6c9; color:#fff; height:.8rem; line-height:.8rem'
                ]
                ,className : opts.className //自定风格
                ,shadeClose:false
                ,content: str
                ,style: 'font-family:微软雅黑; font-size:.28rem'
                ,btn: ['确认', '取消']
                ,success: function(elem){
                    $('.'+opts.className).find('.textarea').find('textarea').focus();
                    $('.'+opts.className).find('.textarea').find('.clear').click(function(){
                        $('.'+opts.className).find('.textarea').find(opts.pop_content).val('');
                    });
                }
                ,yes: function(index){
                    var introduction = $('.'+opts.className).find('.textarea').find(opts.pop_content).val();
                    othis.find(opts.hidden).html(introduction);
                    if(introduction != ''){
                        othis.find(opts.select_text).html(mSubstr(introduction,24));
                    }else{
                        othis.find(opts.select_text).html('请输入'+opts.text_title);
                    }
                    opts.callback(introduction);
                    layer.closeAll();
                    scrollTextarea();
                },no:function(index){
                    scrollTextarea();
                }
            });
        });
        //滚动文本区域
        function scrollTextarea(){
            var dHeight = $(window).height();
            var currThis = othis.height();
            $('html,body').scrollTo({scrollTop:othis.offset().top,top: (dHeight - currThis)/2 });
        };
        return this;
    };
})(Zepto);